<template>
  <div class="module">
      <div>
        <div class="along">
          <el-row>
             <el-button @click="loginOne()" class="along-one">登录</el-button>
             <el-button @click="loginTwo()" class="along-one">注册</el-button>
          </el-row>
        </div>
        <div v-if="isLogin">
          <Login v-model:message="message"></Login>
        </div>
        <div v-if="isRegister">
          <Registor></Registor>
        </div>  
      </div>
      <div>
         
          <Admin/>
      </div>
  </div>
</template>

<script setup>
import { provide, reactive,toRefs,onMounted,getCurrentInstance} from "vue";
import Login from "./components/Login.vue";
import Registor from "./components/Registor.vue";
import Admin from "./components/Admin.vue";

// const {ctx} = getCurrentInstance()修改为下面
const {appContext:{config:{globalProperties:$http}}} = getCurrentInstance()
let data = reactive({
      isLogin:false,
      isRegister:false,
    });
let article = reactive({
  aid:"",
  atitle:"",
  acontent:"",
  uid:"",
  publishtime:"",
  deleted:""
})
    
const loginOne=()=>{
  isLogin.value=true
  isRegister.value=false
}
const loginTwo=()=>{
  isLogin.value=false
  isRegister.value=true
}
onMounted(async() => {
      await $http.$http.get(`/article/getAllArticle`).then((res) => {
        console.log(res)
        article = res
      },()=>{
        alert("数据请求失败")
      })
    })

provide('islogin',{isLogin,changeit:()=>{isLogin.value=false}});
provide('isRegister',{isRegister,changeit2:()=>{isRegister.value=false}});
provide('article',article);

let{isLogin,isRegister} = toRefs(data)
</script>

<style lang="less" scoped>
</style>
